Filtering suggested structured queries on online social networks

ABSTRACT

In one embodiment, a method includes accessing a social graph comprising a plurality of nodes and a plurality of edges connecting the nodes, receiving from a user an unstructured text query, generating a set of structured queries based on the text query, calculating a quality score based on the text query and the structured query for each structured query in the set, and filtering the set to remove each structured query having a quality score less than a threshold score.

TECHNICAL FIELD

This disclosure generally relates to social graphs and performingsearches for objects within a social-networking environment.

BACKGROUND

A social-networking system, which may include a social-networkingwebsite, may enable its users (such as persons or organizations) tointeract with it and with each other through it. The social-networkingsystem may, with input from a user, create and store in thesocial-networking system a user profile associated with the user. Theuser profile may include demographic information, communication-channelinformation, and information on personal interests of the user. Thesocial-networking system may also, with input from a user, create andstore a record of relationships of the user with other users of thesocial-networking system, as well as provide services (e.g. wall posts,photo-sharing, event organization, messaging, games, or advertisements)to facilitate social interaction between or among users.

The social-networking system may transmit over one or more networkscontent or messages related to its services to a mobile or othercomputing device of a user. A user may also install softwareapplications on a mobile or other computing device of the user foraccessing a user profile of the user and other data within thesocial-networking system. The social-networking system may generate apersonalized set of content objects to display to a user, such as anewsfeed of aggregated stories of other users connected to the user.

Social-graph analysis views social relationships in terms of networktheory consisting of nodes and edges. Nodes represent the individualactors within the networks, and edges represent the relationshipsbetween the actors. The resulting graph-based structures are often verycomplex. There can be many types of nodes and many types of edges forconnecting nodes. In its simplest form, a social graph is a map of allof the relevant edges between all the nodes being studied.

SUMMARY OF PARTICULAR EMBODIMENTS

In particular embodiments, in response to a text query received from auser, a social-networking system may generate structured queriescomprising query tokens that correspond to identified social-graphelements. By providing suggested structured queries in response to auser's text query, the social-networking system may provide a powerfulway for users of an online social network to search for elementsrepresented in a social graph based on their social-graph attributes andtheir relation to various social-graph elements.

In particular embodiments, the social-networking system may receive anunstructured text query from a user. In response, the social-networkingsystem may parse the text query and generate one or more structuredqueries based on the text query. These structured queries may then befiltered based on the quality of each structured query. When parsingcertain unstructured text queries, the social-networking system maygenerate low-quality or irrelevant structured queries in response. Thismay happen when the text query contains terms that do not match wellwith the grammar model, such that when the term is parsed by the grammarmodel, it is matched to irrelevant query tokens. Since these low-qualitystructured queries may be ridiculous or embarrassing, and may bedesirable to filter out these queries before they are sent back to thequerying user as suggestions. Filtering may be done by analyzing andscoring each structured based on a variety of factors that signal aparticular suggested query may be of low-quality or irrelevant. Eachstructured query may be scored based on the text query itself and thestructured query. Structured queries having a poor quality score may befiltered out, such that only high-quality structured queries arepresented to the querying user. The structured queries remaining afterfiltering may then be transmitted and displayed to the user, where theuser can then select an appropriate query to search for the desiredcontent.

BRIEF DESCRIPTION OF THE DRAWINGS

FIG. 1 illustrates an example network environment associated with asocial-networking system.

FIG. 2 illustrates an example social graph.

FIG. 3 illustrates an example webpage of an online social network.

FIGS. 4A-4B illustrate example queries of the online social network.

FIG. 5 illustrates an example method for filtering suggested structuredqueries on an online social network.

FIG. 6 illustrates an example computer system.

DESCRIPTION OF EXAMPLE EMBODIMENTS

System Overview

FIG. 1 illustrates an example network environment 100 associated with asocial-networking system. Network environment 100 includes a clientsystem 130, a social-networking system 160, and a third-party system 170connected to each other by a network 110. Although FIG. 1 illustrates aparticular arrangement of client system 130, social-networking system160, third-party system 170, and network 110, this disclosurecontemplates any suitable arrangement of client system 130,social-networking system 160, third-party system 170, and network 110.As an example and not by way of limitation, two or more of client system130, social-networking system 160, and third-party system 170 may beconnected to each other directly, bypassing network 110. As anotherexample, two or more of client system 130, social-networking system 160,and third-party system 170 may be physically or logically co-locatedwith each other in whole or in part. Moreover, although FIG. 1illustrates a particular number of client systems 130, social-networkingsystems 160, third-party systems 170, and networks 110, this disclosurecontemplates any suitable number of client systems 130,social-networking systems 160, third-party systems 170, and networks110. As an example and not by way of limitation, network environment 100may include multiple client system 130, social-networking systems 160,third-party systems 170, and networks 110.

This disclosure contemplates any suitable network 110. As an example andnot by way of limitation, one or more portions of network 110 mayinclude an ad hoc network, an intranet, an extranet, a virtual privatenetwork (VPN), a local area network (LAN), a wireless LAN (WLAN), a widearea network (WAN), a wireless WAN (WWAN), a metropolitan area network(MAN), a portion of the Internet, a portion of the Public SwitchedTelephone Network (PSTN), a cellular telephone network, or a combinationof two or more of these. Network 110 may include one or more networks110.

Links 150 may connect client system 130, social-networking system 160,and third-party system 170 to communication network 110 or to eachother. This disclosure contemplates any suitable links 150. Inparticular embodiments, one or more links 150 include one or morewireline (such as for example Digital Subscriber Line (DSL) or Data OverCable Service Interface Specification (DOCSIS)), wireless (such as forexample Wi-Fi or Worldwide Interoperability for Microwave Access(WiMAX)), or optical (such as for example Synchronous Optical Network(SONET) or Synchronous Digital Hierarchy (SDH)) links. In particularembodiments, one or more links 150 each include an ad hoc network, anintranet, an extranet, a VPN, a LAN, a WLAN, a WAN, a WWAN, a MAN, aportion of the Internet, a portion of the PSTN, a cellulartechnology-based network, a satellite communications technology-basednetwork, another link 150, or a combination of two or more such links150. Links 150 need not necessarily be the same throughout networkenvironment 100. One or more first links 150 may differ in one or morerespects from one or more second links 150.

In particular embodiments, client system 130 may be an electronic deviceincluding hardware, software, or embedded logic components or acombination of two or more such components and capable of carrying outthe appropriate functionalities implemented or supported by clientsystem 130. As an example and not by way of limitation, a client system130 may include a computer system such as a desktop computer, notebookor laptop computer, netbook, a tablet computer, e-book reader, GPSdevice, camera, personal digital assistant (PDA), handheld electronicdevice, cellular telephone, smartphone, other suitable electronicdevice, or any suitable combination thereof. This disclosurecontemplates any suitable client systems 130. A client system 130 mayenable a network user at client system 130 to access network 110. Aclient system 130 may enable its user to communicate with other users atother client systems 130.

In particular embodiments, client system 130 may include a web browser132, such as MICROSOFT INTERNET EXPLORER, GOOGLE CHROME or MOZILLAFIREFOX, and may have one or more add-ons, plug-ins, or otherextensions, such as TOOLBAR or YAHOO TOOLBAR. A user at client system130 may enter a Uniform Resource Locator (URL) or other addressdirecting the web browser 132 to a particular server (such as server162, or a server associated with a third-party system 170), and the webbrowser 132 may generate a Hyper Text Transfer Protocol (HTTP) requestand communicate the HTTP request to server. The server may accept theHTTP request and communicate to client system 130 one or more Hyper TextMarkup Language (HTML) files responsive to the HTTP request. Clientsystem 130 may render a webpage based on the HTML files from the serverfor presentation to the user. This disclosure contemplates any suitablewebpage files. As an example and not by way of limitation, webpages mayrender from HTML files, Extensible Hyper Text Markup Language (XHTML)files, or Extensible Markup Language (XML) files, according toparticular needs. Such pages may also execute scripts such as, forexample and without limitation, those written in JAVASCRIPT, JAVA,MICROSOFT SILVERLIGHT, combinations of markup language and scripts suchas AJAX (Asynchronous JAVASCRIPT and XML), and the like. Herein,reference to a webpage encompasses one or more corresponding webpagefiles (which a browser may use to render the webpage) and vice versa,where appropriate.

In particular embodiments, social-networking system 160 may be anetwork-addressable computing system that can host an online socialnetwork. Social-networking system 160 may generate, store, receive, andsend social-networking data, such as, for example, user-profile data,concept-profile data, social-graph information, or other suitable datarelated to the online social network. Social-networking system 160 maybe accessed by the other components of network environment 100 eitherdirectly or via network 110. In particular embodiments,social-networking system 160 may include one or more servers 162. Eachserver 162 may be a unitary server or a distributed server spanningmultiple computers or multiple datacenters. Servers 162 may be ofvarious types, such as, for example and without limitation, web server,news server, mail server, message server, advertising server, fileserver, application server, exchange server, database server, proxyserver, another server suitable for performing functions or processesdescribed herein, or any combination thereof. In particular embodiments,each server 162 may include hardware, software, or embedded logiccomponents or a combination of two or more such components for carryingout the appropriate functionalities implemented or supported by server162. In particular embodiments, social-networking system 164 may includeone or more data stores 164. Data stores 164 may be used to storevarious types of information. In particular embodiments, the informationstored in data stores 164 may be organized according to specific datastructures. In particular embodiments, each data store 164 may be arelational, columnar, correlation, or other suitable database. Althoughthis disclosure describes or illustrates particular types of databases,this disclosure contemplates any suitable types of databases. Particularembodiments may provide interfaces that enable a client system 130, asocial-networking system 160, or a third-party system 170 to manage,retrieve, modify, add, or delete, the information stored in data store164.

In particular embodiments, social-networking system 160 may store one ormore social graphs in one or more data stores 164. In particularembodiments, a social graph may include multiple nodes—which may includemultiple user nodes (each corresponding to a particular user) ormultiple concept nodes (each corresponding to a particular concept)—andmultiple edges connecting the nodes. Social-networking system 160 mayprovide users of the online social network the ability to communicateand interact with other users. In particular embodiments, users may jointhe online social network via social-networking system 160 and then addconnections (e.g., relationships) to a number of other users ofsocial-networking system 160 whom they want to be connected to. Herein,the term “friend” may refer to any other user of social-networkingsystem 160 with whom a user has formed a connection, association, orrelationship via social-networking system 160.

In particular embodiments, social-networking system 160 may provideusers with the ability to take actions on various types of items orobjects, supported by social-networking system 160. As an example andnot by way of limitation, the items and objects may include groups orsocial networks to which users of social-networking system 160 maybelong, events or calendar entries in which a user might be interested,computer-based applications that a user may use, transactions that allowusers to buy or sell items via the service, interactions withadvertisements that a user may perform, or other suitable items orobjects. A user may interact with anything that is capable of beingrepresented in social-networking system 160 or by an external system ofthird-party system 170, which is separate from social-networking system160 and coupled to social-networking system 160 via a network 110.

In particular embodiments, social-networking system 160 may be capableof linking a variety of entities. As an example and not by way oflimitation, social-networking system 160 may enable users to interactwith each other as well as receive content from third-party systems 170or other entities, or to allow users to interact with these entitiesthrough an application programming interfaces (API) or othercommunication channels.

In particular embodiments, a third-party system 170 may include one ormore types of servers, one or more data stores, one or more interfaces,including but not limited to APIs, one or more web services, one or morecontent sources, one or more networks, or any other suitable components,e.g., that servers may communicate with. A third-party system 170 may beoperated by a different entity from an entity operatingsocial-networking system 160. In particular embodiments, however,social-networking system 160 and third-party systems 170 may operate inconjunction with each other to provide social-networking services tousers of social-networking system 160 or third-party systems 170. Inthis sense, social-networking system 160 may provide a platform, orbackbone, which other systems, such as third-party systems 170, may useto provide social-networking services and functionality to users acrossthe Internet.

In particular embodiments, a third-party system 170 may include athird-party content object provider. A third-party content objectprovider may include one or more sources of content objects, which maybe communicated to a client system 130. As an example and not by way oflimitation, content objects may include information regarding things oractivities of interest to the user, such as, for example, movie showtimes, movie reviews, restaurant reviews, restaurant menus, productinformation and reviews, or other suitable information. As anotherexample and not by way of limitation, content objects may includeincentive content objects, such as coupons, discount tickets, giftcertificates, or other suitable incentive objects.

In particular embodiments, social-networking system 160 also includesuser-generated content objects, which may enhance a user's interactionswith social-networking system 160. User-generated content may includeanything a user can add, upload, send, or “post” to social-networkingsystem 160. As an example and not by way of limitation, a usercommunicates posts to social-networking system 160 from a client system130. Posts may include data such as status updates or other textualdata, location information, photos, videos, links, music or othersimilar data or media. Content may also be added to social-networkingsystem 160 by a third-party through a “communication channel,” such as anewsfeed or stream.

In particular embodiments, social-networking system 160 may include avariety of servers, sub-systems, programs, modules, logs, and datastores. In particular embodiments, social-networking system 160 mayinclude one or more of the following: a web server, action logger,API-request server, relevance-and-ranking engine, content-objectclassifier, notification controller, action log,third-party-content-object-exposure log, inference module,authorization/privacy server, search module, advertisement-targetingmodule, user-interface module, user-profile store, connection store,third-party content store, or location store. Social-networking system160 may also include suitable components such as network interfaces,security mechanisms, load balancers, failover servers,management-and-network-operations consoles, other suitable components,or any suitable combination thereof. In particular embodiments,social-networking system 160 may include one or more user-profile storesfor storing user profiles. A user profile may include, for example,biographic information, demographic information, behavioral information,social information, or other types of descriptive information, such aswork experience, educational history, hobbies or preferences, interests,affinities, or location. Interest information may include interestsrelated to one or more categories. Categories may be general orspecific. As an example and not by way of limitation, if a user “likes”an article about a brand of shoes the category may be the brand, or thegeneral category of “shoes” or “clothing.” A connection store may beused for storing connection information about users. The connectioninformation may indicate users who have similar or common workexperience, group memberships, hobbies, educational history, or are inany way related or share common attributes. The connection informationmay also include user-defined connections between different users andcontent (both internal and external). A web server may be used forlinking social-networking system 160 to one or more client systems 130or one or more third-party system 170 via network 110. The web servermay include a mail server or other messaging functionality for receivingand routing messages between social-networking system 160 and one ormore client systems 130. An API-request server may allow a third-partysystem 170 to access information from social-networking system 160 bycalling one or more APIs. An action logger may be used to receivecommunications from a web server about a user's actions on or offsocial-networking system 160. In conjunction with the action log, athird-party-content-object log may be maintained of user exposures tothird-party-content objects. A notification controller may provideinformation regarding content objects to a client system 130.Information may be pushed to a client system 130 as notifications, orinformation may be pulled from client system 130 responsive to a requestreceived from client system 130. Authorization servers may be used toenforce one or more privacy settings of the users of social-networkingsystem 160. A privacy setting of a user determines how particularinformation associated with a user can be shared. The authorizationserver may allow users to opt in to or opt out of having their actionslogged by social-networking system 160 or shared with other systems(e.g., third-party system 170), such as, for example, by settingappropriate privacy settings. Third-party-content-object stores may beused to store content objects received from third parties, such as athird-party system 170. Location stores may be used for storing locationinformation received from client systems 130 associated with users.Advertisement-pricing modules may combine social information, thecurrent time, location information, or other suitable information toprovide relevant advertisements, in the form of notifications, to auser.

Social Graphs

FIG. 2 illustrates example social graph 200. In particular embodiments,social-networking system 160 may store one or more social graphs 200 inone or more data stores. In particular embodiments, social graph 200 mayinclude multiple nodes—which may include multiple user nodes 202 ormultiple concept nodes 204—and multiple edges 206 connecting the nodes.Example social graph 200 illustrated in FIG. 2 is shown, for didacticpurposes, in a two-dimensional visual map representation. In particularembodiments, a social-networking system 160, client system 130, orthird-party system 170 may access social graph 200 and relatedsocial-graph information for suitable applications. The nodes and edgesof social graph 200 may be stored as data objects, for example, in adata store (such as a social-graph database). Such a data store mayinclude one or more searchable or queryable indexes of nodes or edges ofsocial graph 200.

In particular embodiments, a user node 202 may correspond to a user ofsocial-networking system 160. As an example and not by way oflimitation, a user may be an individual (human user), an entity (e.g.,an enterprise, business, or third-party application), or a group (e.g.,of individuals or entities) that interacts or communicates with or oversocial-networking system 160. In particular embodiments, when a userregisters for an account with social-networking system 160,social-networking system 160 may create a user node 202 corresponding tothe user, and store the user node 202 in one or more data stores. Usersand user nodes 202 described herein may, where appropriate, refer toregistered users and user nodes 202 associated with registered users. Inaddition or as an alternative, users and user nodes 202 described hereinmay, where appropriate, refer to users that have not registered withsocial-networking system 160. In particular embodiments, a user node 202may be associated with information provided by a user or informationgathered by various systems, including social-networking system 160. Asan example and not by way of limitation, a user may provide his or hername, profile picture, contact information, birth date, sex, maritalstatus, family status, employment, education background, preferences,interests, or other demographic information. In particular embodiments,a user node 202 may be associated with one or more data objectscorresponding to information associated with a user. In particularembodiments, a user node 202 may correspond to one or more webpages.

In particular embodiments, a concept node 204 may correspond to aconcept. As an example and not by way of limitation, a concept maycorrespond to a place (such as, for example, a movie theater,restaurant, landmark, or city); a website (such as, for example, awebsite associated with social-network system 160 or a third-partywebsite associated with a web-application server); an entity (such as,for example, a person, business, group, sports team, or celebrity); aresource (such as, for example, an audio file, video file, digitalphoto, text file, structured document, or application) which may belocated within social-networking system 160 or on an external server,such as a web-application server; real or intellectual property (suchas, for example, a sculpture, painting, movie, game, song, idea,photograph, or written work); a game; an activity; an idea or theory;another suitable concept; or two or more such concepts. A concept node204 may be associated with information of a concept provided by a useror information gathered by various systems, including social-networkingsystem 160. As an example and not by way of limitation, information of aconcept may include a name or a title; one or more images (e.g., animage of the cover page of a book); a location (e.g., an address or ageographical location); a website (which may be associated with a URL);contact information (e.g., a phone number or an email address); othersuitable concept information; or any suitable combination of suchinformation. In particular embodiments, a concept node 204 may beassociated with one or more data objects corresponding to informationassociated with concept node 204. In particular embodiments, a conceptnode 204 may correspond to one or more webpages.

In particular embodiments, a node in social graph 200 may represent orbe represented by a webpage (which may be referred to as a “profilepage”). Profile pages may be hosted by or accessible tosocial-networking system 160. Profile pages may also be hosted onthird-party websites associated with a third-party server 170. As anexample and not by way of limitation, a profile page corresponding to aparticular external webpage may be the particular external webpage andthe profile page may correspond to a particular concept node 204.Profile pages may be viewable by all or a selected subset of otherusers. As an example and not by way of limitation, a user node 202 mayhave a corresponding user-profile page in which the corresponding usermay add content, make declarations, or otherwise express himself orherself. As another example and not by way of limitation, a concept node204 may have a corresponding concept-profile page in which one or moreusers may add content, make declarations, or express themselves,particularly in relation to the concept corresponding to concept node204.

In particular embodiments, a concept node 204 may represent athird-party webpage or resource hosted by a third-party system 170. Thethird-party webpage or resource may include, among other elements,content, a selectable or other icon, or other inter-actable object(which may be implemented, for example, in JavaScript, AJAX, or PHPcodes) representing an action or activity. As an example and not by wayof limitation, a third-party webpage may include a selectable icon suchas “like,” “check in,” “eat,” “recommend,” or another suitable action oractivity. A user viewing the third-party webpage may perform an actionby selecting one of the icons (e.g., “eat”), causing a client system 130to transmit to social-networking system 160 a message indicating theuser's action. In response to the message, social-networking system 160may create an edge (e.g., an “eat” edge) between a user node 202corresponding to the user and a concept node 204 corresponding to thethird-party webpage or resource and store edge 206 in one or more datastores.

In particular embodiments, a pair of nodes in social graph 200 may beconnected to each other by one or more edges 206. An edge 206 connectinga pair of nodes may represent a relationship between the pair of nodes.In particular embodiments, an edge 206 may include or represent one ormore data objects or attributes corresponding to the relationshipbetween a pair of nodes. As an example and not by way of limitation, afirst user may indicate that a second user is a “friend” of the firstuser. In response to this indication, social-networking system 160 maytransmit a “friend request” to the second user. If the second userconfirms the “friend request,” social-networking system 160 may createan edge 206 connecting the first user's user node 202 to the seconduser's user node 202 in social graph 200 and store edge 206 associal-graph information in one or more of data stores 24. In theexample of FIG. 2, social graph 200 includes an edge 206 indicating afriend relation between user nodes 202 of user “A” and user “B” and anedge indicating a friend relation between user nodes 202 of user “C” anduser “B.” Although this disclosure describes or illustrates particularedges 206 with particular attributes connecting particular user nodes202, this disclosure contemplates any suitable edges 206 with anysuitable attributes connecting user nodes 202. As an example and not byway of limitation, an edge 206 may represent a friendship, familyrelationship, business or employment relationship, fan relationship,follower relationship, visitor relationship, subscriber relationship,superior/subordinate relationship, reciprocal relationship,non-reciprocal relationship, another suitable type of relationship, ortwo or more such relationships. Moreover, although this disclosuregenerally describes nodes as being connected, this disclosure alsodescribes users or concepts as being connected. Herein, references tousers or concepts being connected may, where appropriate, refer to thenodes corresponding to those users or concepts being connected in socialgraph 200 by one or more edges 206.

In particular embodiments, an edge 206 between a user node 202 and aconcept node 204 may represent a particular action or activity performedby a user associated with user node 202 toward a concept associated witha concept node 204. As an example and not by way of limitation, asillustrated in FIG. 2, a user may “like,” “attended,” “played,”“listened,” “cooked,” “worked at,” or “watched” a concept, each of whichmay correspond to a edge type or subtype. A concept-profile pagecorresponding to a concept node 204 may include, for example, aselectable “check in” icon (such as, for example, a clickable “check in”icon) or a selectable “add to favorites” icon. Similarly, after a userclicks these icons, social-networking system 160 may create a “favorite”edge or a “check in” edge in response to a user's action correspondingto a respective action. As another example and not by way of limitation,a user (user “C”) may listen to a particular song (“Imagine”) using aparticular application (SPOTIFY, which is an online music application).In this case, social-networking system 160 may create a “listened” edge206 and a “used” edge (as illustrated in FIG. 2) between user nodes 202corresponding to the user and concept nodes 204 corresponding to thesong and application to indicate that the user listened to the song andused the application. Moreover, social-networking system 160 may createa “played” edge 206 (as illustrated in FIG. 2) between concept nodes 204corresponding to the song and the application to indicate that theparticular song was played by the particular application. In this case,“played” edge 206 corresponds to an action performed by an externalapplication (SPOTIFY) on an external audio file (the song “Imagine”).Although this disclosure describes particular edges 206 with particularattributes connecting user nodes 202 and concept nodes 204, thisdisclosure contemplates any suitable edges 206 with any suitableattributes connecting user nodes 202 and concept nodes 204. Moreover,although this disclosure describes edges between a user node 202 and aconcept node 204 representing a single relationship, this disclosurecontemplates edges between a user node 202 and a concept node 204representing one or more relationships. As an example and not by way oflimitation, an edge 206 may represent both that a user likes and hasused at a particular concept. Alternatively, another edge 206 mayrepresent each type of relationship (or multiples of a singlerelationship) between a user node 202 and a concept node 204 (asillustrated in FIG. 2 between user node 202 for user “E” and conceptnode 204 for “SPOTIFY”).

In particular embodiments, social-networking system 160 may create anedge 206 between a user node 202 and a concept node 204 in social graph200. As an example and not by way of limitation, a user viewing aconcept-profile page (such as, for example, by using a web browser or aspecial-purpose application hosted by the user's client system 130) mayindicate that he or she likes the concept represented by the conceptnode 204 by clicking or selecting a “Like” icon, which may cause theuser's client system 130 to transmit to social-networking system 160 amessage indicating the user's liking of the concept associated with theconcept-profile page. In response to the message, social-networkingsystem 160 may create an edge 206 between user node 202 associated withthe user and concept node 204, as illustrated by “like” edge 206 betweenthe user and concept node 204. In particular embodiments,social-networking system 160 may store an edge 206 in one or more datastores. In particular embodiments, an edge 206 may be automaticallyformed by social-networking system 160 in response to a particular useraction. As an example and not by way of limitation, if a first useruploads a picture, watches a movie, or listens to a song, an edge 206may be formed between user node 202 corresponding to the first user andconcept nodes 204 corresponding to those concepts. Although thisdisclosure describes forming particular edges 206 in particular manners,this disclosure contemplates forming any suitable edges 206 in anysuitable manner.

Typeahead Processes

In particular embodiments, one or more client-side and/or backend(server-side) processes implement and utilize a “typeahead” feature toautomatically attempt to match concepts corresponding to respectiveexisting user nodes 202 or concept nodes 204 to information currentlybeing entered by a user in an input form rendered in conjunction with arequested webpage, such as a user-profile page, which may be hosted oraccessible in, by social-networking system 160. In particularembodiments, as a user is entering text to make a declaration, thetypeahead feature attempts to match the string of textual charactersbeing entered in the declaration to strings of characters (e.g., names)corresponding to existing concepts (or users) and corresponding concept(or user) nodes in the social graph 200. In particular embodiments, whena match is found, the typeahead feature may automatically populate theform with a reference to the node (such as, for example, the node name,node ID, or another suitable reference or identifier) of the existingnode.

In particular embodiments, as a user types or otherwise enters text intoa form used to add content or make declarations in various sections ofthe user's profile page or other page, the typeahead process may work inconjunction with one or more frontend (client-side) and/or backend(server-side) typeahead processes (hereinafter referred to simply as“typeahead process”) executing at (or within) social-networking system160 (e.g., within servers 162), to interactively and virtuallyinstantaneously (as appearing to the user) attempt to auto-populate theform with a term or terms corresponding to names of existingsocial-graph entities, or terms associated with existing social-graphentities, determined to be the most relevant or best match to thecharacters of text entered by the user as the user enters the charactersof text. Utilizing the social-graph information in a social-graphdatabase or information extracted and indexed from the social-graphdatabase, including information associated with nodes and edges, thetypeahead processes, in conjunction with the information from thesocial-graph database, as well as potentially in conjunction withvarious others processes, applications, or databases located within orexecuting within social-networking system 160, are able to predict auser's intended declaration with a high degree of precision. However,social-networking system 160 also provides user's with the freedom toenter any declaration they wish enabling users to express themselvesfreely.

In particular embodiments, as a user enters text characters into a formbox or other field, the typeahead processes may attempt to identifyexisting social-graph elements (e.g., user nodes 202, concept nodes 204,or edges 206) that match the string of characters entered in the user'sdeclaration as the user is entering the characters. In particularembodiments, as the user enters characters into a form box, thetypeahead process may read the string of entered textual characters. Aseach keystroke is made, the frontend-typeahead process may transmit theentered character string as a request (or call) to the backend-typeaheadprocess executing within social-networking system 160. In particularembodiments, the typeahead processes may communicate via AJAX(Asynchronous JavaScript and XML) or other suitable techniques, andparticularly, asynchronous techniques. In one particular embodiment, therequest is, or comprises, an XMLHTTPRequest (XHR) enabling quick anddynamic sending and fetching of results. In particular embodiments, thetypeahead process also transmits before, after, or with the request asection identifier (section ID) that identifies the particular sectionof the particular page in which the user is making the declaration. Inparticular embodiments, a user ID parameter may also be sent, but thismay be unnecessary in some embodiments, as the user is already “known”based on he or she logging into social-networking system 160.

In particular embodiments, the typeahead process may use one or morematching algorithms to attempt to identify matching social-graphelements. In particular embodiments, when a match or matches are found,the typeahead process may transmit a response (which may utilize AJAX orother suitable techniques) to the user's client system 130 that mayinclude, for example, the names (name strings) of the matchingsocial-graph elements as well as, potentially, other metadata associatedwith the matching social-graph elements. As an example and not by way oflimitation, if a user entering the characters “dat” into a query field,the typeahead process may display a drop-down menu that displays namesof matching existing profile pages and respective user nodes 202 orconcept nodes 204 (e.g., a profile page named or devoted to “dating”),which the user can then click on or otherwise select thereby confirmingthe desire to declare the matched user or concept name corresponding tothe selected node. As another example and not by way of limitation, uponclicking “dating,” the typeahead process may auto-populate, or causesthe web browser 132 to auto-populate, the query field with thedeclaration “Dating”. In particular embodiments, the typeahead processmay simply auto-populate the field with the name or other identifier ofthe top-ranked match rather than display a drop-down menu. The user maythen confirm the auto-populated declaration simply by keying “enter” onhis or her keyboard or by clicking on the auto-populated declaration.

More information on typeahead processes may be found in U.S. patentapplication Ser. No. 12/763,162, filed 19 Apr. 2010, and U.S. patentapplication Ser. No. 13/556,072, filed 23 Jul. 2012, which areincorporated by reference.

Structured Search Queries

FIG. 3 illustrates an example webpage of an online social network. Inparticular embodiments, a user may submit a query to the social-networksystem 160 by inputting a text query into query field 350. A user of anonline social network may search for information relating to a specificsubject matter (e.g., users, concepts, external content or resource) byproviding a short phrase describing the subject matter, often referredto as a “search query,” to a search engine. The query may be anunstructured text query and may comprise one or more text strings or oneor more n-grams. In general, a user may input any character string intoquery field 350 to search for content on social-networking system 160that matches the text query. Social-networking system 160 may thensearch a data store 164 (or, more particularly, a social-graph database)to identify content matching the query. The search engine may conduct asearch based on the query phrase using various search algorithms andgenerate search results that identify resources or content (e.g.,user-profile pages, content-profile pages, or external resources) thatare most likely to be related to the search query. To conduct a search,a user may input or transmit a search query to the search engine. Inresponse, the search engine may identify one or more resources that arelikely to be related to the search query, which may collectively bereferred to as a “search result” identified for the search query. Theidentified content may include, for example, social-graph entities(i.e., user nodes 202, concept nodes 204, edges 206), profile pages,external webpages, or any combination thereof. Social-networking system160 may then generate a search results webpage with search resultscorresponding to the identified content. The search results may bepresented to the user, often in the form of a list of links onsearch-results webpage, each link being associated with a differentwebpage that contains some of the identified resources or content. Inparticular embodiments, each link in the search results may be in theform of a Uniform Resource Locator (URL) that specifies where thecorresponding webpage is located and the mechanism for retrieving it.Social-networking system 160 may then transmit the search resultswebpage to the user's web browser 132 on the user's client system 130.The user may then click on the URL links or otherwise select the contentfrom the search results webpage to access the content fromsocial-networking system 160 or from an external system, as appropriate.The resources may be ranked and presented to the user according to theirrelative degrees of relevance to the search query. The search resultsmay also be ranked and presented to the user according to their relativedegree of relevance to the user. In other words, the search results maybe personalized for the querying user based on, for example,social-graph information, user information, search or browsing historyof the user, or other suitable information related to the user. Inparticular embodiments, ranking of the resources may be determined by aranking algorithm implemented by the search engine. As an example andnot by way of limitation, resources that are more relevant to the searchquery or to the user may be ranked higher than the resources that areless relevant to the search query or the user. In particularembodiments, the search engine may limit its search to resources andcontent on the online social network. However, in particularembodiments, the search engine may also search for resources or contentson other sources, such as a third-party system 170, the internet orWorld Wide Web, or other suitable sources. Although this disclosuredescribes querying social-networking system 160 in a particular manner,this disclosure contemplates querying social-networking system 160 inany suitable manner.

In particular embodiments, the typeahead processes described herein maybe applied to search queries entered by a user. As an example and not byway of limitation, as a user enters text characters into a search field,a typeahead process may attempt to identify one or more user nodes 202,concept nodes 204, or edges 206 that match the string of charactersentered search field as the user is entering the characters. As thetypeahead process receives requests or calls including a string orn-gram from the text query, the typeahead process may perform or causesto be performed a search to identify existing social-graph elements(i.e., user nodes 202, concept nodes 204, edges 206) having respectivenames, types, categories, or other identifiers matching the enteredtext. The typeahead process may use one or more matching algorithms toattempt to identify matching nodes or edges. When a match or matches arefound, the typeahead process may transmit a response to the user'sclient system 130 that may include, for example, the names (namestrings) of the matching nodes as well as, potentially, other metadataassociated with the matching nodes. The typeahead process may thendisplay a drop-down menu 300 that displays names of matching existingprofile pages and respective user nodes 202 or concept nodes 204, anddisplays names of matching edges 206 that may connect to the matchinguser nodes 202 or concept nodes 204, which the user can then click on orotherwise select thereby confirming the desire to search for the matcheduser or concept name corresponding to the selected node, or to searchfor users or concepts connected to the matched users or concepts by thematching edges. Alternatively, the typeahead process may simplyauto-populate the form with the name or other identifier of thetop-ranked match rather than display a drop-down menu 300. The user maythen confirm the auto-populated declaration simply by keying “enter” ona keyboard or by clicking on the auto-populated declaration. Upon userconfirmation of the matching nodes and edges, the typeahead process maytransmit a request that informs social-networking system 160 of theuser's confirmation of a query containing the matching social-graphelements. In response to the request transmitted, social-networkingsystem 160 may automatically (or alternately based on an instruction inthe request) call or otherwise search a social-graph database for thematching social-graph elements, or for social-graph elements connectedto the matching social-graph elements as appropriate. Although thisdisclosure describes applying the typeahead processes to search queriesin a particular manner, this disclosure contemplates applying thetypeahead processes to search queries in any suitable manner.

In connection with search queries and search results, particularembodiments may utilize one or more systems, components, elements,functions, methods, operations, or steps disclosed in U.S. patentapplication Ser. No. 11/503,093, filed 11 Aug. 2006, U.S. patentapplication Ser. No. 12/977,027, filed 22 Dec. 2010, and U.S. patentapplication Ser. No. 12/978,265, filed 23 Dec. 2010, which areincorporated by reference.

Parsing Text Queries and Rendering Structured Queries

FIGS. 4A-4B illustrate example queries of the online social network. Inparticular embodiments, in response to a text query received from afirst user (i.e., the querying user), social-networking system 160 maygenerate one or more structured queries rendered in a natural-languagesyntax, where each structured query includes query tokens thatcorrespond to one or more identified social-graph elements. Anatural-language structured query may be generated using a context-freegrammar model. These structured queries may be based on stringsgenerated by the grammars of the grammar model, such that they arerendered with references to the appropriate social-graph elements usinga natural-language syntax. The structured queries may be transmitted tothe first user and displayed in a drop-down menu 300 (via, for example,a client-side typeahead process), where the first user can then selectan appropriate query to search for the desired content. FIGS. 4A-4Billustrate various example text queries in query field 350 and variousstructured queries generated in response in drop-down menus 300. Byproviding suggested structured queries in response to a user's textquery, social-networking system 160 may provide a powerful way for usersof the online social network to search for elements represented in thesocial graph 200 based on their social-graph attributes and theirrelation to various social-graph elements. Structured queries may allowa querying user to search for content that is connected to particularusers or concepts in the social graph 200 by particular edge types.Although this disclosure describes and FIGS. 4A-4B illustrate generatingparticular structured queries in a particular manner, this disclosurecontemplates generating any suitable structured queries in any suitablemanner. More information on parsing queries, grammar models, andgenerating structured queries may be found in U.S. patent applicationSer. No. 13/556,060, filed 23 Jul. 2012, U.S. patent application Ser.No. 13/674,695, filed 12 Nov. 2012, U.S. patent application Ser. No.13/731,866, filed 31 Dec. 2012, and U.S. patent application Ser. No.13/732,175, filed 31 Dec. 2012, each of which is incorporated byreference herein.

In particular embodiments, social-networking system 160 may receive froma querying/first user (corresponding to a first user node 202) anunstructured text query. As an example and not by way of limitation, afirst user may want to search for other users who: (1) are first-degreefriends of the first user; and (2) are associated with StanfordUniversity (i.e., the user nodes 202 are connected by an edge 206 to theconcept node 204 corresponding to the school “Stanford”). The first usermay then enter a text query “friends stanford” into query field 350, asillustrated in FIGS. 4A-4B. As the first user enters this text queryinto query field 350, social-networking system 160 may provide varioussuggested structured queries, as illustrated in drop-down menus 300. Asused herein, an unstructured text query refers to a simple text stringinputted by a user. The text query may, of course, be structured withrespect to standard language/grammar rules (e.g. English languagegrammar). However, the text query will ordinarily be unstructured withrespect to social-graph elements. In other words, a simple text querywill not ordinarily include embedded references to particularsocial-graph elements. Thus, as used herein, a structured query refersto a query that contains references to particular social-graph elements,allowing the search engine to search based on the identified elements.Furthermore, the text query may be unstructured with respect to formalquery syntax. In other words, a simple text query will not necessarilybe in the format of a query command that is directly executable by asearch engine. Although this disclosure describes receiving particularqueries in a particular manner, this disclosure contemplates receivingany suitable queries in any suitable manner.

In particular embodiments, social-networking system 160 may parse theunstructured text query (also simply referred to as a search query)received from the first user (i.e., the querying user) to identify oneor more n-grams. In general, an n-gram is a contiguous sequence of nitems from a given sequence of text or speech. The items may becharacters, phonemes, syllables, letters, words, base pairs, prefixes,or other identifiable items from the sequence of text or speech. Then-gram may comprise one or more characters of text (letters, numbers,punctuation, etc.) entered by the querying user. An n-gram of size onecan be referred to as a “unigram,” of size two can be referred to as a“bigram” or “digram,” of size three can be referred to as a “trigram,”and so on. Each n-gram may include one or more parts from the text queryreceived from the querying user. In particular embodiments, each n-grammay comprise a character string (e.g., one or more characters of text)entered by the first user. As an example and not by way of limitation,social-networking system 160 may parse the text query “friends stanford”to identify the following n-grams: friends; stanford; friends stanford.As another example and not by way of limitation, social-networkingsystem 160 may parse the text query “friends in palo alto” to identifythe following n-grams: friends; in; palo; alto; friends in; in palo;palo alto; friend in palo; in palo also; friends in palo alto. Inparticular embodiments, each n-gram may comprise a contiguous sequenceof n items from the text query. Although this disclosure describesparsing particular queries in a particular manner, this disclosurecontemplates parsing any suitable queries in any suitable manner.

In particular embodiments, social-networking system 160 may determine orcalculate, for each n-gram identified in the text query, a score thatthe n-gram corresponds to a social-graph element. The score may be, forexample, a confidence score, a probability, a quality, a ranking,another suitable type of score, or any combination thereof. As anexample and not by way of limitation, social-networking system 160 maydetermine a probability score (also referred to simply as a“probability”) that the n-gram corresponds to a social-graph element,such as a user node 202, a concept node 204, or an edge 206 of socialgraph 200. The probability score may indicate the level of similarity orrelevance between the n-gram and a particular social-graph element.There may be many different ways to calculate the probability. Thepresent disclosure contemplates any suitable method to calculate aprobability score for an n-gram identified in a search query. Inparticular embodiments, social-networking system 160 may determine aprobability, p, that an n-gram corresponds to a particular social-graphelement. The probability, p, may be calculated as the probability ofcorresponding to a particular social-graph element, k, given aparticular search query, X. In other words, the probability may becalculated as p=(k|X). As an example and not by way of limitation, aprobability that an n-gram corresponds to a social-graph element maycalculated as an probability score denoted as p_(i,j,k). The input maybe a text query X=(x₁, x₂, . . . , x_(N)), and a set of classes. Foreach (i:j) and a class k, social-networking system 160 may computep_(i,j,k)=p(class(x_(i:j))=k|X). In particular embodiments, theidentified social-graph elements may be used to generate a query commandthat is executable by a search engine. The query command may be astructured semantic query with defined functions that accept specificarguments. As an example and not by way of limitation, the text query“friend me mark” could be parsed to form the query command:intersect(friend(me), friend(Mark)). In other words, the query islooking for nodes in the social graph that intersect the querying user(“me”) and the user “Mark” (i.e., those user nodes 202 that areconnected to both the user node 202 of the querying user by afriend-type edge 206 and the user node 202 for the user “Mark” by afriend-type edge 206). Although this disclosure describes determiningwhether n-grams correspond to social-graph elements in a particularmanner, this disclosure contemplates determining whether n-gramscorrespond to social-graph elements in any suitable manner. Moreover,although this disclosure describes determining whether an n-gramcorresponds to a social-graph element using a particular type of score,this disclosure contemplates determining whether an n-gram correspondsto a social-graph element using any suitable type of score.

In particular embodiments, social-networking system 160 may identify oneor more edges 206 having a probability greater than an edge-thresholdprobability. Each of the identified edges 206 may correspond to at leastone of the n-grams. As an example and not by way of limitation, then-gram may only be identified as corresponding to an edge, k, ifp_(i,j,k)>p_(edge threshold). Furthermore, each of the identified edges206 may be connected to at least one of the identified nodes. In otherwords, social-networking system 160 may only identify edges 206 oredge-types that are connected to user nodes 202 or concept nodes 204that have previously been identified as corresponding to a particularn-gram. Edges 206 or edge-types that are not connected to any previouslyidentified node are typically unlikely to correspond to a particularn-gram in a search query. By filtering out or ignoring these edges 206and edge-types, social-networking system 160 may more efficiently searchthe social graph 200 for relevant social-graph elements. Although thisdisclosure describes identifying edges 206 that correspond to n-grams ina particular manner, this disclosure contemplates identifying edges 206that correspond to n-grams in any suitable manner.

In particular embodiments, social-networking system 160 may identify oneor more user nodes 202 or concept nodes 204 having a probability greaterthan a node-threshold probability. Each of the identified nodes maycorrespond to at least one of the n-grams. As an example and not by wayof limitation, the n-gram may only be identified as corresponding to anode, k, if p_(i,j,k)>p_(node-threshold). Furthermore, each of theidentified user nodes 202 or concept nodes 204 may be connected to atleast one of the identified edges 206. In other words, social-networkingsystem 160 may only identify nodes or nodes-types that are connected toedges 206 that have previously been identified as corresponding to aparticular n-gram. Nodes or node-types that are not connected to anypreviously identified edges 206 are typically unlikely to correspond toa particular n-gram in a search query. By filtering out or ignoringthese nodes and node-types, social-networking system 160 may moreefficiently search the social graph 200 for relevant social-graphelements. Although this disclosure describes identifying nodes thatcorrespond to n-grams in a particular manner, this disclosurecontemplates identifying nodes that correspond to n-grams in anysuitable manner.

In particular embodiments, social-networking system 160 may access acontext-free grammar model comprising a plurality of grammars. Eachgrammar of the grammar model may comprise one or more non-terminaltokens (or “non-terminal symbols”) and one or more terminal tokens (or“terminal symbols”/“query tokens”), where particular non-terminal tokensmay be replaced by terminal tokens. A grammar model is a set offormation rules for strings in a formal language. In particularembodiments, the plurality of grammars may be visualized as a grammarforest organized as an ordered tree, with the internal nodescorresponding to non-terminal tokens and the leaf nodes corresponding toterminal tokens. Each grammar may be represented as a sub-tree withinthe grammar forest, where the grammars are adjoining each other vianon-terminal tokens. Thus, two or more grammars may be a sub-forestwithin the grammar forest. Although this disclosure describes accessingparticular grammars, this disclosure contemplates any suitable grammars.

In particular embodiments, social-networking system 160 may generate oneor more strings using one or more grammars. To generate a string in thelanguage, one begins with a string consisting of only a single startsymbol. The production rules are then applied in any order, until astring that contains neither the start symbol nor designatednon-terminal symbols is produced. In a context-free grammar, theproduction of each non-terminal symbol of the grammar is independent ofwhat is produced by other non-terminal symbols of the grammar. Thenon-terminal symbols may be replaced with terminal symbols (i.e.,terminal tokens or query tokens). Some of the query tokens may besocial-graph tokens, which may correspond to identified nodes oridentified edges, as described previously. A string generated by thegrammar may then be used as the basis for a structured query containingreferences to the identified nodes or identified edges. The stringgenerated by the grammar may be rendered in a natural-language syntax,such that a structured query based on the string is also rendered innatural language. A context-free grammar is a grammar in which theleft-hand side of each production rule consists of only a singlenon-terminal symbol. A probabilistic context-free grammar is a tuple

Σ, N, S, P

, where the disjoint sets Σ and N specify the terminal and non-terminalsymbols, respectively, with Sε N being the start symbol. P is the set ofproductions, which take the form E→ξ(p), with EεN, ξε(Σ∪ N)⁺, andp=Pr(E→ξ), the probability that E will be expanded into the string ξ.The sum of probabilities p over all expansions of a given non-terminal Emust be one. Although this disclosure describes generating strings in aparticular manner, this disclosure contemplates generating strings inany suitable manner.

In particular embodiments, social-networking system 160 may identify oneor more query tokens corresponding to the previously identified nodesand edges. In other words, if an identified node or identified edge maybe used as a query token in a particular grammar, that query token maybe identified by social-networking system 160. Query tokens may includegrammar tokens or social-graph tokens. A grammar token is a query tokencorresponding to text inserted to render in a natural-language syntax. Asocial-graph token is a query token corresponding to a particular nodeor edge of social graph 200. As an example and not by way of limitation,an example grammar may be: [user][user-filter][school]. The non-terminalsymbols [user], [user-filter], and [school] could then be determinedbased n-grams in the received text query. For the text query “friendsstanford”, this query could be parsed by using the grammar as, forexample, “[friends][who][go to][Stanford University]” or“[friends][who][work at][Stanford University]”. In this example, thequery tokens [friends], [go to], [work at], and [Stanford University]may all be social-graph tokens that correspond to particular nodes andedges of social-graph 200. Similarly, the query token [who] may be agrammar token, which was inserted by the grammar in order to render thestructured query in a natural-language syntax. In both the example casesabove, if the n-grams of the received text query could be used as querytokens, then these query tokens may be identified by social-networkingsystem 160. Although this disclosure describes identifying particularquery tokens in a particular manner, this disclosure contemplatesidentifying any suitable query tokens in any suitable manner.

In particular embodiments, social-networking system 160 may select oneor more grammars having at least one query token corresponding to eachof the previously identified nodes and edges. Only particular grammarsmay be used depending on the n-grams identified in the text query. Sothe terminal tokens of all available grammars should be examined to findthose that match the identified n-grams from the text query. In otherwords, if a particular grammar can use all of the identified nodes andedges as query tokens, that grammar may be selected by social-networkingsystem 160 as a possible grammar to use for generating a structuredquery. This is effectively a type of bottom-up parsing, where thepossible query tokens are used to determine the applicable grammar toapply to the query. As an example and not by way of limitation, for thetext query “friends stanford”, the social-networking system may identifythe query tokens of [friends] and [Stanford University]. Terminal tokensof the grammars from the grammar model may be identified, as previouslydiscussed. Any grammar that is able to use both the [friends] and the[Stanford University] tokens may then be selected. For example, thegrammar [user][user-filter][school] may be selected because this grammarcould use the [friends] and the [Stanford University] tokens as querytokens, such as by forming the strings “friends who go to StanfordUniversity” or “friends who work at Stanford University”. Thus, if then-grams of the received text query could be used as query tokens in thegrammars, then these grammars may be selected by social-networkingsystem 160. Similarly, if the received text query comprises n-grams thatcould not be used as query tokens in the grammar, that grammar may notbe selected. Although this disclosure describes selecting particulargrammars in a particular manner, this disclosure contemplates selectingany suitable grammars in any suitable manner.

In particular embodiments, social-networking system 160 may select oneor more grammars by analyzing a grammar forest formed by a plurality ofgrammars. The grammar forest may be organized as an ordered treecomprising a plurality of non-terminal tokens and a plurality ofterminal tokens. Each grammar may be represented as a sub-tree withinthe grammar forest, and each sub-tree may adjoin other sub-trees via oneor more additional non-terminal tokens. As an example and not by way oflimitation, social-networking system 160 may start by identifying allthe terminal tokens (i.e., query tokens) in the grammar forest thatcorrespond to identified nodes and edges corresponding to portions of atext query. Once these query tokens in the grammar forest have beenidentified, social-networking system 160 may then traverse the grammarforest up from each of these query tokens to identify one or moreintersecting non-terminal tokens. Once a non-terminal token has beenidentified where paths from all the query tokens intersect, thatintersecting non-terminal token may be selected, and the one or moregrammars adjoined to that intersecting non-terminal token in the grammarforest may then be selected. Although this disclosure describesselecting grammars in a particular manner, this disclosure contemplatesselecting grammars in any suitable manner.

In particular embodiments, social-networking system 160 may generate asemantic tree corresponding to the text query from the querying user.The semantic tree may include each identified query token thatcorresponds to a previously identified node or edge, and may alsoinclude an intersect token. The semantic tree may also includenon-terminal tokens as appropriate connecting the query tokens to theintersect token. As an example and not by way of limitation, the textquery “friends stanford” may be parsed into the query command(intersect(school:<Stanford University>, friends_of:<me>)). In otherwords, the query is looking for nodes in the social graph that intersectboth friends of the querying user (“me”) (i.e., those user nodes 202that are connected to the user node 202 of the querying user by afriend-type edge 206) and the concept node 204 for Stanford University.Although this disclosure describes generating particular semantic treesin a particular manner, this disclosure contemplates generating anysuitable semantic trees in any suitable manner.

In particular embodiments, social-networking system 160 may analyze agrammar forest comprising a plurality of grammars to identify one ormore sets of non-terminal tokens and query tokens that substantiallymatch a semantic tree corresponding to a query, where each set has anon-terminal token corresponding to the intersect token of the semantictree. Social-networking system 160 may then select one or more of thegrammars in the grammar forest adjoining the non-terminal tokencorresponding to the intersect token. The algorithm will attempt to findthe lowest-cost multi-path in the grammar forest that leads to anintersect token, and the intersect token corresponding to thislowest-cost multi-path may be preferentially selected over otherintersect tokens (if any). Although this disclosure describes analyzingparticular grammar forests in a particular manner, this disclosurecontemplates analyzing any suitable grammar forests in any suitablemanner.

In particular embodiments, social-networking system 160 may determine ascore for each selected grammar. The score may be, for example, aconfidence score, a probability, a quality, a ranking, another suitabletype of score, or any combination thereof. The score may be based on theindividual scores or probabilities associated with the query tokens usedin the selected grammar. A grammar may have a higher relative score ifit uses query tokens with relatively higher individual scores. Inparticular embodiments, social-networking system 160 may determine ascore for a selected grammar based on social-graph affinity. Affinitymay represent the strength of a relationship or level of interestbetween particular objects associated with the online social network,such as users, concepts, content, actions, advertisements, other objectsassociated with the online social network, or any suitable combinationthereof. Grammars with query tokens corresponding to social-graphelements having a higher affinity with respect to the querying user maybe scored more highly than grammars with query tokens corresponding tosocial-graph elements having a lower affinity with respect to thequerying user. In particular embodiments, social-networking system 160may determine a score for a selected grammar based on the lengths of thepaths traversed in order to identify the intersect token correspondingto the selected grammar. Grammars with lower-cost multi-paths (i.e.,shorter paths) may be scored more highly than grammars with high-costmulti-paths (i.e., longer paths). In particular embodiments,social-networking system 160 may determine a score for a selectedgrammar based on advertising sponsorship. An advertiser (such as, forexample, the user or administrator of a particular profile pagecorresponding to a particular node) may sponsor a particular node suchthat a grammar that includes a query token referencing that sponsorednode may be scored more highly. Although this disclosure describesdetermining particular scores for particular grammars in a particularmanner, this disclosure contemplates determining any suitable scores forany suitable grammars in any suitable manner. In connection withsocial-graph affinity and affinity coefficients, particular embodimentsmay utilize one or more systems, components, elements, functions,methods, operations, or steps disclosed in U.S. patent application Ser.No. 11/503,093, filed 11 Aug. 2006, U.S. patent application Ser. No.12/977,027, filed 22 Dec. 2010, U.S. patent application Ser. No.12/978,265, filed 23 Dec. 2010, and U.S. patent application Ser. No.13/632,869, filed 1 Oct. 2012, each of which is incorporated byreference.

In particular embodiments, social-networking system 160 may select oneor more grammars having a score greater than a grammar-threshold score.Each of the selected grammars may contain query tokens that correspondto each of the identified nodes or identified edges (which correspond ton-grams of the received text query). In particular embodiments, thegrammars may be ranked based on their determined scores, and onlygrammars within a threshold rank may be selected (e.g., top seven).Although this disclosure describes selecting grammars in a particularmanner, this disclosure contemplates selecting grammars in any suitablemanner.

In particular embodiments, social-networking system 160 may generate oneor more structured queries corresponding to the selected grammars (e.g.,those grammars having a score greater than a grammar-threshold score).Each structured query may be based on a string generated by thecorresponding selected grammar. As an example and not by way oflimitation, in response to the text query “friends stanford”, thegrammar [user][user-filter][school] may generate a string “friends whogo to Stanford University”, where the non-terminal tokens [user],[user-filter], [school] of the grammar have been replaced by theterminal tokens [friends], [who go to], and [Stanford University],respectively, to generate the string. In particular embodiments, astring that is generated by grammar using a natural-language syntax maybe rendered as a structured query in natural language. As an example andnot by way of limitation, the structured query from the previous exampleuses the terminal token [who go to], which uses a natural-languagesyntax so that the string rendered by grammar is in natural language.The natural-language string generated by a grammar may then be renderedto form a structured query by modifying the query tokens correspondingto social-graph element to include references to those social-graphelements. As an example and not by way of limitation, the string“friends who go to Stanford University” may be rendered so that thequery token for “Stanford University” appears in the structured query asa reference to the concept node 204 corresponding to the school“Stanford University”, where the reference may be include highlighting,an inline link, a snippet, another suitable reference, or anycombination thereof. Each structured query may comprise query tokenscorresponding to the corresponding selected grammar, where these querytokens correspond to one or more of the identified edges 206 and one ormore of the identified nodes. Generating structured queries is describedmore below.

Generating and Filtering Structured Search Queries

In particular embodiments, social-networking system 160 may generate aset of structured queries based on the text query received from thequerying user. The generated structured queries may be based onnatural-language strings generated by one or more context-free grammars,as described previously. Each structured query may comprise query tokensfrom the corresponding grammar. The query tokens may be social-graphtokens corresponding to one or more of the identified user nodes 202 orone or more of the identified edges 206. As an example and not by way oflimitation, in response to the text query, “show me friends of mygirlfriend,” the social-networking system 160 may generate a structuredquery “Friends of Stephanie,” where “Friends” and “Stephanie” in thestructured query are references corresponding to particular social-graphelements. The reference to “Stephanie” would correspond to a particularuser node 202 (i.e., a user node 202 corresponding to the user“Stephanie”, which is connected to a user node 202 of the querying userby a in-relationship-type edge 206), while the reference to “friends”would correspond to “friend” edges 206 connecting that user node 202 toother user nodes 202 (i.e., edges 206 connecting to “Stephanie's”first-degree friends). In particular embodiments, social-networkingsystem 160 may filter the set of structured queries generated inresponse to the text query based on the quality of each structuredquery. When parsing certain unstructured text queries, social-networkingsystem 160 may generate low-quality or irrelevant structured queries inresponse. This may happen when the text query contains terms that do notmatch well with the grammar model, such that when the term is parsed bythe grammar model, it is matched to irrelevant query tokens. As anexample and not by way of limitation, a text query for “tall people”might not generate any relevant structured queries because the terms maynot be parsed well by the grammar model if these terms do not match anyquery tokens used in the grammar model (e.g., the terms to not match anysocial-graph elements), or possibly only have low-quality matches (e.g.,a low-quality match may be a structured query referencing a page orgroup named “Tall People!”). These low-quality suggested queries may beridiculous or embarrassing, may contain query tokens that false matchesor are irrelevant, or may simply not match with the query intent of theuser. Regardless, it may be desirable to filter out these structuredqueries before they are sent to the querying user as suggested queries.In order to avoid sending such queries to the user as suggestions, eachstructured query may be analyzed and scored based on a variety offactors that signal a particular suggested query may be of low-qualityor irrelevant. Each structured query in the set generated bysocial-networking system 160 may be scored based on the text queryitself and the structured query. Structured queries having a poorquality score may be filtered out, such that only high-qualitystructured queries are presented to the querying user. Although thisdisclosure describes generating particular structured queries in aparticular manner, this disclosure contemplates generating any suitablestructured queries in any suitable manner.

In particular embodiments, social-networking system 160 may generate aset of structured queries based on a text query received from a user ofthe online social network. Each structured query may comprise one ormore query tokens, which may be grammar tokens or social-graph tokenscorresponding to the identified concept nodes 204 and one or more of theidentified edges 206. These structured queries may allow thesocial-networking system 160 to more efficiently search for resourcesand content related to the online social network (such as, for example,profile pages) by searching for content objects connected to orotherwise related to the identified concept nodes 204 and the identifiededges 206. As an example and not by way of limitation, in response tothe text query, “friends like facebook,” the social-networking system160 may generate a structured query “My friends who like Facebook”. Inthis example, the references in the structured query to “friends,”“like,” and “Facebook” are social-graph tokens corresponding toparticular social-graph elements as described previously (i.e., a“friend” edge 206, a “like” edge 206, and a “Facebook” concept node204). Similarly, the references to “my” and “who” are grammar tokens,which are included in the structured query so that it is rendered in anatural-language syntax. In particular embodiments, thesocial-networking system 160 may generate a plurality of structuredqueries, where the structured queries may comprise references todifferent identified concept nodes 204 or different identified edges206. As an example and not by way of limitation, continuing with theprevious example, in addition to the structured query “My friends wholike Facebook,” the social-networking system 160 may also generate astructured query “My friends who like Facebook Culinary Team,” where“Facebook Culinary Team” in the structured query is a query tokencorresponding to yet another social-graph element. In particularembodiments, social-networking system 160 may rank the generatedstructured queries. The structured queries may be ranked based on avariety of factors. In particular embodiments, the social-networkingsystem 160 may ranks structured queries based on advertisingsponsorship. An advertiser (such as, for example, the user oradministrator of a particular profile page corresponding to a particularnode) may sponsor a particular node such that a structured queryreferencing that node may be ranked more highly. Although thisdisclosure describes generating particular structured queries in aparticular manner, this disclosure contemplates generating any suitablestructured queries in any suitable manner.

In particular embodiments, social-networking system 160 may calculate aquality score for a structured query based on the text query and thestructured query. The quality score may be, for example, a confidencescore, a probability, a quality, a ranking, another suitable type ofscore, or any combination thereof. As an example and not by way oflimitation, when determining a quality score, s, for a structured query,social-networking system 160 may factor in the text query received fromthe querying user and the structured query generated in response to thetext query. Thus, the quality score corresponding to a particularstructured query, s, given a particular search query, X, and theparticular structured query, Q, may be calculated as s=(X, Q). Thequality score may be calculated in a variety of ways and using a varietyof factors. As an example and not by way of limitation, the qualityscore for a structured query may be calculated based in part on one ormore of the generation cost, the normalized cost, the grammar-insertioncost, the entity-numerosity cost, the language-model score, theentity-insertion cost, other suitable factors, or any combinationthereof. In particular embodiments, social-networking system 160 maycalculate the quality score for a structured query based on thegeneration cost of the structured query. A cost may be associated witheach query token used to generate a structured query. As more querytokens are used to construct the structured query, the cost of the querymay increase. Furthermore, different query tokens and types of tokensmay have different costs. When generating a set of structured queries inresponse to a text query, social-networking system 160 may attempt togenerate structured queries having the lowest generation cost possible.This may be done, for example, similarly to, or in conjunction with,selecting grammars from the grammar model. Grammars having lower-costmulti-paths may generate structured queries having lower generationcosts, where the shortest-path grammar should produce the structuredquery having the lowest generation cost. Although this disclosuredescribes determining quality scores for particular structured queriesin a particular manner, this disclosure contemplates determining qualityscores for any suitable structured queries in any suitable manner.

In particular embodiments, social-networking system 160 may calculatethe quality score for a structured query based on a normalized cost ofthe structured query. The number of terms in the text query receivedfrom the querying user (e.g., the number of identified n-grams in thetext query) should normally be proportional to the number of querytokens in the structured query generated in response to that text query.Ideally, the ratio of n-grams to query tokes should approach unity(1:1). Thus, if the grammar model parses the text query and generates astructured query having substantially more query tokens than expected,it is likely that the structured query is of low quality. In otherwords, if the grammar model has to insert a significant number of querytokens in order to identify a grammar that matches the text query, thenthe structured query generated by that grammar is likely of low quality.Similarly, for longer text queries, it is expected that the structuredquery generated in response to the text query would contain more querytokens, and thus have a higher generation cost. Thus, the cost forgenerating the structured query may be normalized based on the length ofthe text query, such that high-cost structured queries may be identifiedas being of low quality if the cost is disproportionate to the length ofthe text query. Structured queries having high normalized costs indicatethat they are of low quality, such that a high normalize cost correlatesto a low quality score. In particular embodiments, social-networkingsystem 160 may determine the number of n-grams in the text queryreceived from the querying user and determine the number of query tokensin the structured query. Social-networking system 160 may then calculatea normalized cost based on the ratio of the number of n-grams in thetext query to the number of query tokens in the structured query. As anexample and not by way of limitation, for the text query “friendsstanford”, social-networking system 160 may generate a structured querysuch as “Friends who go to Stanford University”, as illustrated in FIG.4B. Social-networking system 160 may then determine that the text queryhas two n-grams: “friends” and “stanford”, which were parsed by thegrammar model to generate a structured query having three query tokens:[friends], [who go to], and [Stanford University]. Thus, the grammarmodel inserted a single query token, [who go to], in order to match thetext query to string. Since the ratio of query tokens to n-grams in thetext query is relatively low (3:2), this structured query may have arelatively low normalized cost, indicating it is a relativelyhigh-quality structured query. As another example and not by way oflimitation, in response to the text query “friends stanford”,social-networking system 160 may generate a structured query such as“People who are friends with people who go to Stanford University”. Inthis case, the structured query contains significantly more query tokensthan the prior example. When the cost of generating this structuredquery is normalized based on the number of n-grams in the text query, itwill have a high normalized cost, which indicates it should have a lowquality score and thus should be filtered out. Although this disclosuredescribes calculating quality scores for structured queries in aparticular manner, this disclosure contemplates calculating qualityscores for structured queries in any suitable manner.

In particular embodiments, social-networking system 160 may calculatethe quality score for a structured query based on a grammar-insertioncost of the structured query. When generating a structured query usingthe grammar model, the number of grammar tokens inserted to generate thestructured query should ideally be minimized. Thus, if the grammar modelparses the text query and generates a structured query havingsignificantly more grammar tokens than expected, it is likely that thestructured query is of low quality. In other words, if the grammar modelhas to insert a significant number of grammar tokens in order toidentify a grammar that matches the text query (and thus render thestructured query in a natural-language syntax), then the structuredquery generated by that grammar is likely of low quality. Structuredqueries having high grammar-insertion costs (i.e., the cost associatedwith inserting grammar tokens into the structured query) indicate thatthey are of low quality, such that a high grammar-insertion costcorrelates to a low quality score. In particular embodiments,social-networking system 160 may determine a number of n-grams in thetext query received from the querying user, and determine a number ofgrammar tokens and social-graph tokens in the structured query.Social-networking system 160 may then calculate a grammar-insertion costbased on the ratio of the number of grammar tokens to the number ofsocial-graph tokens normalized by the number of n-grams. As an exampleand not by way of limitation, for the text query “girls i have dated”,social-networking system 160 may generate a structured query such as“Female users I have been friends with who like the Dating app”. Here,the n-gram “girls” matches to the query token [Female users] and then-gram “dated” matches to [Dating app] (albeit, this itself may be alow-quality match). However, in order to match the n-gram “i have”, thegrammar model has to insert the grammar tokens [I have been], [friendswith], and [who like]. Thus, there is a high grammar insertion costassociated with this structured query because of the relatively highnumber of grammar tokens inserted in order to generate the query,indicating it is a relatively low-quality structured query. Althoughthis disclosure describes calculating quality scores for structuredqueries in a particular manner, this disclosure contemplates calculatingquality scores for structured queries in any suitable manner.

In particular embodiments, social-networking system 160 may calculatethe quality score for a structured query based on an entity-numerositycost of the structured query. When generating a structured queryingusing the grammar model, some, but not all, of the social-graph tokensshould correspond to nodes of the social graph 200. When parsing atypical unstructured text query, it is expected that the structuredquery generated based on the text query should include a variety ofquery tokens, including some grammar tokens, some social-graph tokensfor edges 206 or edge-types, and some social-graph tokens for user nodes202 or concept nodes 204. However, if the parsing matches too many termsto nodes, or otherwise produces a structured query with a relativelylarge number of query tokens corresponding to nodes, it is likely thatsome of those nodes are false matches which don't match the query intentof the querying user. In other words, if a suggested structured querycontains references to too many nodes, it is likely of low quality.Structured queries having high entity-numerosity costs (i.e., the costassociated with inserting social-graph tokens corresponding to nodesrelatively to the other query tokens) indicate that they are of lowquality, such that a high entity-numerosity cost correlates to a lowquality score. In particular embodiments, social-networking system 160may determine a number of social-graph tokens that correspond to nodesin the structured query. Social-networking system 160 may thencalculated an entity-numerosity cost based on the number of social-graphtokens in the structured query. As an example and not by way oflimitation, for the text query “girls i have dated from stanford”,social-networking system 160 may generate a structured query such as“People from Stanford, California who like the ‘Girls I Have Dated’page”. Here, the structured query includes social-graph tokens for thecity [Stanford, California] and the page [Girls I Have Dated], each ofwhich corresponds to a particular concept node 204 of social graph 200.Thus, the n-gram “from stanford” is being matched by the grammar modelto the query tokens [People from][Stanford, California], and the n-gram“girls i have dated” is being matched to the social-graph token for theconcept node 204 corresponding to the page [Girls I Have Dated] (notethat this itself may be a low-quality match). Relative to the length ofthe text query, the structured query contains a large number ofsocial-graph tokens for nodes. Furthermore, a single token, [Girls IHave Dated] is being matched to a large portion of the unstructured textquery. Thus, there is a high entity-numerosity cost associated with thisstructured query because of the relatively high number of social-graphtokens for nodes inserted in order to generate the query, indicating itis a relatively low-quality structured query. Although this disclosuredescribes calculating quality scores for structured queries in aparticular manner, this disclosure contemplates calculating qualityscores for structured queries in any suitable manner.

In particular embodiments, social-networking system 160 may calculatethe quality score for a structured query based on a language-modelscore. The language-model score may be calculated with respect to theidentified terms of the original text query as compared with the querytokens of the structured query. After generating a particular structuredquery, social-networking system 160 may analyze each query token and thequery tokens adjacent to it in the structured query (e.g., the precedingor succeeding tokens) based on the sequence of the terms correspondingto those query tokens from the original text query. The probability thatthe tokens should appear with one or more of the adjacent tokens in thesequence from the original text query can then be analyzed. If thegrammar model has inserted query tokens that are unlikely to appeartogether with adjacent query tokens in the original text query, then thestructured query is likely of low quality. Structured queries having lowlanguage-model scores (i.e., there are query tokens with lowprobabilities of appearing together) indicate that they are of lowquality, such that a low language-model score correlates to a lowquality score. As an example and not by way of limitation,social-networking system 160 may determine a probability, p, of aparticular query token being paired with particular adjacent terms fromthe original query. This calculation may factor in the sequence of termsin the original text query. Thus, the probability that a particularparsing corresponds to a particular query token pairing may be may becalculated as p=(t₁|t₂, . . . , t_(x)), where t₁ is the query tokenbeing analyzed and t₂ . . . t_(x) are the adjacent query tokens 2 to xin the original text query. The individual probabilities for each querytoken may then be used to determine the overall language-model score fora structured query. In particular embodiments, social-networking system160 may determine a probability, for each query token of a structuredquery, that the query token would appear with the adjacent query tokensin the original text query. Social-networking system 160 may thencalculate a language-model score based on the probabilities for thequery tokens. As an example and not by way of limitation, for the textquery “girls i have dated”, social-networking system 160 may generate astructured query such as “Female users I have who use the Dating app”,where the Dating app is a hypothetical application associated with theonline social network with an entity-type [application] (i.e., itcorresponds to a non-terminal token [application]). To calculate theprobability for the query token [Dating app], social-networking system160 may then analyze the other query tokens from the structured querythat correspond to adjacent terms in the original text query. In thiscase, social-networking system 160 may determine the probability that itwould be used the query tokens [Female], [I], and [have] (whichcorrespond to the terms “girls”, “i”, and “have” from the original textquery, respectively) with the query token [Dating app] (or possibly theprobability of using the non-terminal token [application]). Thisprobability may be calculated as p=([Dating app]|([Female], [I],[have])), or the probability of inserting the query token [Dating app]given the preceding query tokens [Female], [I], and [have](alternatively, the probability may be calculated asp=([application]|([Female], [I], [have]))). In this case, there may be alow probability that the query tokens [Female], [I], and [have] would beused before the social-graph token [Dating app], and thus thisstructured query would have a relatively low language-model score,indicating it is a relatively low-quality structured query. Althoughthis disclosure describes calculating quality scores for structuredqueries in a particular manner, this disclosure contemplates calculatingquality scores for structured queries in any suitable manner.

In particular embodiments, social-networking system 160 may calculatethe quality score for a structured query based on an entity-insertioncost of the structured query. When parsing a particular text query, theterms in the text query (e.g., the n-grams in the text query) shouldmatch the query token in the generated structured query as closely aspossible. Thus, changes to the terms or the addition of terms shouldincrease the cost of generating that particular query token, such that astructured query containing such modified tokens may be of low quality.Structured queries having high entity-insertion costs (i.e., the costassociated with inserting or modifying terms from the text query to makeit match a particular query token) indicate that they may be of lowquality, such that a high entity-insertion cost correlates with a lowquality score. In particular embodiments, social-networking system 160may determine, for each social-graph token in the structured query, thenumber of terms inserted by the grammar to match the social-graph tokenwith its corresponding n-gram. As an example and not by way oflimitation, for the text query “girls who like dating”,social-networking system 160 may generate the structured query “Femaleusers who like the ‘Dating in Palo Alto’ app”. Thus, the term “dating”from the text query has been parsed by the grammar model and matched tothe query token for [Dating in Palo Alto] (which may correspond to aparticular concept node 204 for an app). However, in order to make theterm “dating” match this query token, social-networking system 160 hadto insert the addition terms “in Palo Alto” to match with the querytoken [Dating in Palo Alto]. Thus, there is a high entity-insertion costassociated with this structured query because of the relatively highnumber of terms inserted by the grammar model to make the n-gram fromthe text query match the query token in the structured query, indicatingthat it is a relatively low-quality structured query. Although thisdisclosure describes calculating quality scores for structured queriesin a particular manner, this disclosure contemplates calculating qualityscores for structured queries in any suitable manner.

In particular embodiments, social-networking system 160 may send one ormore of the structured queries to the querying user. As an example andnot by way of limitation, after the structured queries are generated,the social-networking system 160 may send one or more of the structuredqueries as a response (which may utilize AJAX or other suitabletechniques) to the user's client system 130 that may include, forexample, the names (name strings) of the referenced social-graphelements, other query limitations (e.g., Boolean operators, etc.), aswell as, potentially, other metadata associated with the referencedsocial-graph elements. The web browser 132 on the querying user's clientsystem 130 may display the sent structured queries in a drop-down menu300, as illustrated in FIGS. 4A-4B. In particular embodiments,social-networking system 160 may send to the first/querying user one ormore of the structured queries from the post-filtered first set. Eachstructured query sent to the first user may have a quality score greaterthan or equal to a threshold quality score. In this way, low-qualitystructured queries may be filtered out (i.e., removed from the set ofstructured queries generated for the user). The remaining structuredqueries after filtering (if any) may then be ranked and one or more ofthese may then be sent to the querying user. In particular embodiments,if fewer than a threshold number of structured queries remain afterfiltering, then social-networking system 160 may generate a web searchquery based on the text query. In this way, if the grammar model failsto produce relevant queries, the querying user is still left with anoption for performing a search. As an example and not by way oflimitation, for the text query “girls i have dated”, social-networkingsystem 160 may generate very few, or even zero, structured queries ofsufficient quality to send to the querying user as suggested queries. Asdescribed previously, the parsing of this text query may produce avariety of low-quality structured queries, each of which may be filteredout by social-networking system 160. Consequently, social-networkingsystem 160 may instead send a suggested query for performing a websearch, such as, for example, “Search the web for ‘girls i have dated’”.If the user selected this suggested query, the query may be transmittedto a web search engine (e.g., BING, GOOGLE, etc.) via an appropriateAPI, where a standard string-matching search may be performed. Resultsmay then be sent back to the social-networking system 160 (e.g., via anAPI) for display to the querying user. Alternatively, when the queryinguser selects the web search option, the user's web browser 132 may beredirect to the webpage for the search engine. In particularembodiments, the sent queries may be presented to the querying user in aranked order, such as, for example, based on a rank previouslydetermined as described above. Structured queries with better rankingsmay be presented in a more prominent position. Furthermore, inparticular embodiments, only structured queries above a threshold rankmay be sent or displayed to the querying user. As an example and not byway of limitation, as illustrated in FIGS. 4A-4B, the structured queriesmay be presented to the querying user in a drop-down menu 300 wherehigher ranked structured queries may be presented at the top of themenu, with lower ranked structured queries presented in descending orderdown the menu. In the examples illustrated in FIGS. 4A-4B, only theseven highest ranked queries are sent and displayed to the user.However, in these examples if there are fewer than seven structuredqueries available to send to the user (e.g., because some of have beenfiltered out due to low quality), then only the available structuredqueries may be sent. Furthermore, when there are fewer than sevenstructured queries, social-networking system 160 may include a suggestedweb search query in the set of suggested queries sent to the queryinguser. In particular embodiments, one or more references in a structuredquery may be highlighted (e.g., outlined, underlined, circled, bolded,italicized, colored, lighted, offset, in caps) in order to indicate itscorrespondence to a particular social-graph element. As an example andnot by way of limitation, as illustrated in FIGS. 4A-4B, the referencesto “Stanford University” and “Stanford, California” are highlighted(outlined) in the structured queries to indicate that it corresponds toa particular concept node 204. Similarly, the references to “Friends”,“like”, “work at”, and “go to” in the structured queries presented indrop-down menu 300 could also be highlighted to indicate that theycorrespond to particular edges 206. Although this disclosure describessending particular structured queries in a particular manner, thisdisclosure contemplates sending any suitable structured queries in anysuitable manner.

In particular embodiments, social-networking system 160 may receive fromthe querying user a selection of one of the structured queries.Alternatively, the social-networking system 160 may receive a structuredquery as a query selected automatically by the system (e.g., a defaultselection) in certain contexts. The nodes and edges referenced in thereceived structured query may be referred to as the selected nodes andselected edges, respectively. As an example and not by way oflimitation, the web browser 132 on the querying user's client system 130may display the transmitted structured queries in a drop-down menu 300,as illustrated in FIGS. 4A-4B, which the user may then click on orotherwise select (e.g., by simply keying “enter” on his keyboard) toindicate the particular structured query the user wants thesocial-networking system 160 to execute. Upon selecting the particularstructured query, the user's client system 130 may call or otherwiseinstruct to the social-networking system 160 to execute the selectedstructured query. As an example and not by way of limitation, inresponse to a selection of a particular structured query,social-networking system 160 may generate a query command based on thestructured query, which may then be sent to one or more data stores 164to search for content objects that match the constraints of the querycommand. Although this disclosure describes receiving selections ofparticular structured queries in a particular manner, this disclosurecontemplates receiving selections of any suitable structured queries inany suitable manner.

FIG. 5 illustrates an example method 500 for filtering suggestedstructured queries on an online social network. The method may begin atstep 510, where social-networking system 160 may access a social graph200 comprising a plurality of nodes and a plurality of edges 206connecting the nodes. The nodes may comprise a first node 202 and aplurality of second nodes (one or more user nodes 202, concepts nodes204, or any combination thereof). At step 520, social-networking system160 may receive from the first user an unstructured text query. The textquery may comprise one or more n-grams. At step 530, social-networkingsystem 160 may generate a first set of structured queries based on thetext query. Each structured query in the first set may correspond to anindentified grammar of a context-free grammar model. Each structuredquery may also comprise one or more grammar tokens or one or moresocial-graph tokens. Each social-graph token may correspond to a node ofthe plurality of nodes or an edge of the plurality of edges. At step540, social-networking system 160 may calculate, for each structuredquery, a quality score based on the text query and the structured query.The quality score may be calculated in any suitable manner describedherein. At step 550, social-networking system 160 may filtering thefirst set to remove each structured query from the first set having aquality score less than a threshold quality score. At step 560,social-networking system 160 may send to the first user one or more ofthe structured queries from the post-filtered first set. Each structuredquery sent to the first user may have a quality score greater than orequal to the threshold quality score. Particular embodiments may repeatone or more steps of the method of FIG. 5, where appropriate. Althoughthis disclosure describes and illustrates particular steps of the methodof FIG. 5 as occurring in a particular order, this disclosurecontemplates any suitable steps of the method of FIG. 5 occurring in anysuitable order. Moreover, although this disclosure describes andillustrates particular components, devices, or systems carrying outparticular steps of the method of FIG. 5, this disclosure contemplatesany suitable combination of any suitable components, devices, or systemscarrying out any suitable steps of the method of FIG. 5.

Systems and Methods

FIG. 6 illustrates an example computer system 600. In particularembodiments, one or more computer systems 600 perform one or more stepsof one or more methods described or illustrated herein. In particularembodiments, one or more computer systems 600 provide functionalitydescribed or illustrated herein. In particular embodiments, softwarerunning on one or more computer systems 600 performs one or more stepsof one or more methods described or illustrated herein or providesfunctionality described or illustrated herein. Particular embodimentsinclude one or more portions of one or more computer systems 600.Herein, reference to a computer system may encompass a computing device,and vice versa, where appropriate. Moreover, reference to a computersystem may encompass one or more computer systems, where appropriate.

This disclosure contemplates any suitable number of computer systems600. This disclosure contemplates computer system 600 taking anysuitable physical form. As example and not by way of limitation,computer system 600 may be an embedded computer system, a system-on-chip(SOC), a single-board computer system (SBC) (such as, for example, acomputer-on-module (COM) or system-on-module (SOM)), a desktop computersystem, a laptop or notebook computer system, an interactive kiosk, amainframe, a mesh of computer systems, a mobile telephone, a personaldigital assistant (PDA), a server, a tablet computer system, or acombination of two or more of these. Where appropriate, computer system600 may include one or more computer systems 600; be unitary ordistributed; span multiple locations; span multiple machines; spanmultiple data centers; or reside in a cloud, which may include one ormore cloud components in one or more networks. Where appropriate, one ormore computer systems 600 may perform without substantial spatial ortemporal limitation one or more steps of one or more methods describedor illustrated herein. As an example and not by way of limitation, oneor more computer systems 600 may perform in real time or in batch modeone or more steps of one or more methods described or illustratedherein. One or more computer systems 600 may perform at different timesor at different locations one or more steps of one or more methodsdescribed or illustrated herein, where appropriate.

In particular embodiments, computer system 600 includes a processor 602,memory 604, storage 606, an input/output (I/O) interface 608, acommunication interface 610, and a bus 612. Although this disclosuredescribes and illustrates a particular computer system having aparticular number of particular components in a particular arrangement,this disclosure contemplates any suitable computer system having anysuitable number of any suitable components in any suitable arrangement.

In particular embodiments, processor 602 includes hardware for executinginstructions, such as those making up a computer program. As an exampleand not by way of limitation, to execute instructions, processor 602 mayretrieve (or fetch) the instructions from an internal register, aninternal cache, memory 604, or storage 606; decode and execute them; andthen write one or more results to an internal register, an internalcache, memory 604, or storage 606. In particular embodiments, processor602 may include one or more internal caches for data, instructions, oraddresses. This disclosure contemplates processor 602 including anysuitable number of any suitable internal caches, where appropriate. Asan example and not by way of limitation, processor 602 may include oneor more instruction caches, one or more data caches, and one or moretranslation lookaside buffers (TLBs). Instructions in the instructioncaches may be copies of instructions in memory 604 or storage 606, andthe instruction caches may speed up retrieval of those instructions byprocessor 602. Data in the data caches may be copies of data in memory604 or storage 606 for instructions executing at processor 602 tooperate on; the results of previous instructions executed at processor602 for access by subsequent instructions executing at processor 602 orfor writing to memory 604 or storage 606; or other suitable data. Thedata caches may speed up read or write operations by processor 602. TheTLBs may speed up virtual-address translation for processor 602. Inparticular embodiments, processor 602 may include one or more internalregisters for data, instructions, or addresses. This disclosurecontemplates processor 602 including any suitable number of any suitableinternal registers, where appropriate. Where appropriate, processor 602may include one or more arithmetic logic units (ALUs); be a multi-coreprocessor; or include one or more processors 602. Although thisdisclosure describes and illustrates a particular processor, thisdisclosure contemplates any suitable processor.

In particular embodiments, memory 604 includes main memory for storinginstructions for processor 602 to execute or data for processor 602 tooperate on. As an example and not by way of limitation, computer system600 may load instructions from storage 606 or another source (such as,for example, another computer system 600) to memory 604. Processor 602may then load the instructions from memory 604 to an internal registeror internal cache. To execute the instructions, processor 602 mayretrieve the instructions from the internal register or internal cacheand decode them. During or after execution of the instructions,processor 602 may write one or more results (which may be intermediateor final results) to the internal register or internal cache. Processor602 may then write one or more of those results to memory 604. Inparticular embodiments, processor 602 executes only instructions in oneor more internal registers or internal caches or in memory 604 (asopposed to storage 606 or elsewhere) and operates only on data in one ormore internal registers or internal caches or in memory 604 (as opposedto storage 606 or elsewhere). One or more memory buses (which may eachinclude an address bus and a data bus) may couple processor 602 tomemory 604. Bus 612 may include one or more memory buses, as describedbelow. In particular embodiments, one or more memory management units(MMUs) reside between processor 602 and memory 604 and facilitateaccesses to memory 604 requested by processor 602. In particularembodiments, memory 604 includes random access memory (RAM). This RAMmay be volatile memory, where appropriate Where appropriate, this RAMmay be dynamic RAM (DRAM) or static RAM (SRAM). Moreover, whereappropriate, this RAM may be single-ported or multi-ported RAM. Thisdisclosure contemplates any suitable RAM. Memory 604 may include one ormore memories 604, where appropriate. Although this disclosure describesand illustrates particular memory, this disclosure contemplates anysuitable memory.

In particular embodiments, storage 606 includes mass storage for data orinstructions. As an example and not by way of limitation, storage 606may include a hard disk drive (HDD), a floppy disk drive, flash memory,an optical disc, a magneto-optical disc, magnetic tape, or a UniversalSerial Bus (USB) drive or a combination of two or more of these. Storage606 may include removable or non-removable (or fixed) media, whereappropriate. Storage 606 may be internal or external to computer system600, where appropriate. In particular embodiments, storage 606 isnon-volatile, solid-state memory. In particular embodiments, storage 606includes read-only memory (ROM). Where appropriate, this ROM may bemask-programmed ROM, programmable ROM (PROM), erasable PROM (EPROM),electrically erasable PROM (EEPROM), electrically alterable ROM (EAROM),or flash memory or a combination of two or more of these. Thisdisclosure contemplates mass storage 606 taking any suitable physicalform. Storage 606 may include one or more storage control unitsfacilitating communication between processor 602 and storage 606, whereappropriate. Where appropriate, storage 606 may include one or morestorages 606. Although this disclosure describes and illustratesparticular storage, this disclosure contemplates any suitable storage.

In particular embodiments, I/O interface 608 includes hardware,software, or both, providing one or more interfaces for communicationbetween computer system 600 and one or more I/O devices. Computer system600 may include one or more of these I/O devices, where appropriate. Oneor more of these I/O devices may enable communication between a personand computer system 600. As an example and not by way of limitation, anI/O device may include a keyboard, keypad, microphone, monitor, mouse,printer, scanner, speaker, still camera, stylus, tablet, touch screen,trackball, video camera, another suitable I/O device or a combination oftwo or more of these. An I/O device may include one or more sensors.This disclosure contemplates any suitable I/O devices and any suitableI/O interfaces 608 for them. Where appropriate, I/O interface 608 mayinclude one or more device or software drivers enabling processor 602 todrive one or more of these I/O devices. I/O interface 608 may includeone or more I/O interfaces 608, where appropriate. Although thisdisclosure describes and illustrates a particular I/O interface, thisdisclosure contemplates any suitable I/O interface.

In particular embodiments, communication interface 610 includeshardware, software, or both providing one or more interfaces forcommunication (such as, for example, packet-based communication) betweencomputer system 600 and one or more other computer systems 600 or one ormore networks. As an example and not by way of limitation, communicationinterface 610 may include a network interface controller (NIC) ornetwork adapter for communicating with an Ethernet or other wire-basednetwork or a wireless NIC (WNIC) or wireless adapter for communicatingwith a wireless network, such as a WI-FI network. This disclosurecontemplates any suitable network and any suitable communicationinterface 610 for it. As an example and not by way of limitation,computer system 600 may communicate with an ad hoc network, a personalarea network (PAN), a local area network (LAN), a wide area network(WAN), a metropolitan area network (MAN), or one or more portions of theInternet or a combination of two or more of these. One or more portionsof one or more of these networks may be wired or wireless. As anexample, computer system 600 may communicate with a wireless PAN (WPAN)(such as, for example, a BLUETOOTH WPAN), a WI-FI network, a WI-MAXnetwork, a cellular telephone network (such as, for example, a GlobalSystem for Mobile Communications (GSM) network), or other suitablewireless network or a combination of two or more of these. Computersystem 600 may include any suitable communication interface 610 for anyof these networks, where appropriate. Communication interface 610 mayinclude one or more communication interfaces 610, where appropriate.Although this disclosure describes and illustrates a particularcommunication interface, this disclosure contemplates any suitablecommunication interface.

In particular embodiments, bus 612 includes hardware, software, or bothcoupling components of computer system 600 to each other. As an exampleand not by way of limitation, bus 612 may include an AcceleratedGraphics Port (AGP) or other graphics bus, an Enhanced Industry StandardArchitecture (EISA) bus, a front-side bus (FSB), a HYPERTRANSPORT (HT)interconnect, an Industry Standard Architecture (ISA) bus, an INFINIBANDinterconnect, a low-pin-count (LPC) bus, a memory bus, a Micro ChannelArchitecture (MCA) bus, a Peripheral Component Interconnect (PCI) bus, aPCI-Express (PCIe) bus, a serial advanced technology attachment (SATA)bus, a Video Electronics Standards Association local (VLB) bus, oranother suitable bus or a combination of two or more of these. Bus 612may include one or more buses 612, where appropriate. Although thisdisclosure describes and illustrates a particular bus, this disclosurecontemplates any suitable bus or interconnect.

Herein, a computer-readable non-transitory storage medium or media mayinclude one or more semiconductor-based or other integrated circuits(ICs) (such, as for example, field-programmable gate arrays (FPGAs) orapplication-specific ICs (ASICs)), hard disk drives (HDDs), hybrid harddrives (HHDs), optical discs, optical disc drives (ODDs),magneto-optical discs, magneto-optical drives, floppy diskettes, floppydisk drives (FDDs), magnetic tapes, solid-state drives (SSDs),RAM-drives, SECURE DIGITAL cards or drives, any other suitablecomputer-readable non-transitory storage media, or any suitablecombination of two or more of these, where appropriate. Acomputer-readable non-transitory storage medium may be volatile,non-volatile, or a combination of volatile and non-volatile, whereappropriate.

Miscellaneous

Herein, “or” is inclusive and not exclusive, unless expressly indicatedotherwise or indicated otherwise by context. Therefore, herein, “A or B”means “A, B, or both,” unless expressly indicated otherwise or indicatedotherwise by context. Moreover, “and” is both joint and several, unlessexpressly indicated otherwise or indicated otherwise by context.Therefore, herein, “A and B” means “A and B, jointly or severally,”unless expressly indicated otherwise or indicated otherwise by context.

The scope of this disclosure encompasses all changes, substitutions,variations, alterations, and modifications to the example embodimentsdescribed or illustrated herein that a person having ordinary skill inthe art would comprehend. The scope of this disclosure is not limited tothe example embodiments described or illustrated herein. Moreover,although this disclosure describes and illustrates respectiveembodiments herein as including particular components, elements,functions, operations, or steps, any of these embodiments may includeany combination or permutation of any of the components, elements,functions, operations, or steps described or illustrated anywhere hereinthat a person having ordinary skill in the art would comprehend.Furthermore, reference in the appended claims to an apparatus or systemor a component of an apparatus or system being adapted to, arranged to,capable of, configured to, enabled to, operable to, or operative toperform a particular function encompasses that apparatus, system,component, whether or not it or that particular function is activated,turned on, or unlocked, as long as that apparatus, system, or componentis so adapted, arranged, capable, configured, enabled, operable, oroperative.

What is claimed is:
 1. A method comprising, by a computing device:accessing a social graph comprising a plurality of nodes and a pluralityof edges connecting the nodes, each of the edges between two of thenodes representing a single degree of separation between them, the nodescomprising: a first node corresponding to a first user associated withan online social network; and a plurality of second nodes that eachcorrespond to a concept or a second user associated with the onlinesocial network; receiving, from a client device of the first user, anunstructured text query inputted by the first user; generating a firstset of structured queries based on the text query, each structured queryin the first set corresponding to a grammar of a context-free grammarmodel, wherein each structured query in the first set is based on anatural-language string generated by a grammar of the context-freegrammar model and comprises one or more grammar tokens and one or moresocial-graph tokens, and wherein each social-graph token corresponds toa node of the plurality of nodes or an edge of the plurality of edges;calculating, for each structured query in the first set, a quality scorebased on the text query and the structured query; filtering the firstset to remove each structured query from the first set having a qualityscore less than a threshold quality score; and sending, to the clientdevice of the first user, one or more of the structured queries from thepost-filtered first set, wherein each structured query sent to the firstuser has a quality score greater than or equal to the threshold qualityscore.
 2. The method of claim 1, wherein calculating a quality scorecomprises, for each structured query: determining a first number ofn-grams in the text query; determining a second number of query tokensin the structured query; and calculating a normalized cost based on theratio of the first number to the second number, wherein the qualityscore is based on the normalized cost.
 3. The method of claim 1, whereincalculating a quality score comprises, for each structured query:determining a first number of n-grams in the text query; determining asecond number of grammar tokens in the structured query; determining athird number of social-graph tokens in the structured query; andcalculating a grammar-insertion cost based on the ratio of the secondnumber to the third number normalized by the first number, wherein thequality score is based on the grammar-insertion cost.
 4. The method ofclaim 1, wherein calculating a quality score comprises, for eachstructured query: determining a first number of social-graph tokenscorresponding to nodes in the structured query; and calculating anentity-numerosity cost based on the first number, wherein the qualityscore is based on the entity-numerosity cost.
 5. The method of claim 1,wherein calculating a quality score comprises, for each structuredquery: for each query token of the structured query, wherein the querytoken corresponds to a first term of the text query, determining aprobability that the query token pairs with one or more other querytokens of the structured query that correspond to one or more secondterms of the text query, wherein the one or more second terms areadjacent to the first term in the text query; and calculating alanguage-model score based on the probabilities for each query token,wherein the quality score is based on the language-model score.
 6. Themethod of claim 1, wherein: the text query comprises one or moren-grams, and wherein each social-graph token corresponds to at least oneof the n-grams; and calculating an entity-insertion cost for eachsocial-graph token based on a first number of terms inserted by thegrammar to match the social-graph token with its corresponding n-gram,wherein the quality score is based on the entity-insertion cost.
 7. Themethod of claim 1, wherein if fewer than a threshold number ofstructured queries remain after filtering the first set, then generatinga web search query based on the text query.
 8. The method of claim 1,further comprising: identifying one or more edges or one or more secondnodes, each of the identified edges or identified nodes corresponding toat least a portion of the unstructured text query; accessing acontext-free grammar model comprising a plurality of grammars, eachgrammar comprising one or more query tokens, wherein each query token isa grammar or a social-graph token; and identifying one or more grammars,each identified grammar having one or more query tokens corresponding toat least one of the identified second nodes or identified edges.
 9. Themethod of claim 8, further comprising: determining a first score foreach identified grammar; and wherein each structured query in the firstset corresponds to an identified grammar having first score greater thana grammar-threshold score, wherein the structured query is based on astring generated by the identified grammar, each structured querycomprising the query tokens of the corresponding identified grammar,wherein one or more of the query tokens of the structured querycorresponds to at least one of the identified second nodes or identifiededges.
 10. The method of claim 8, wherein the text query comprises oneor more n-grams, and wherein each of the identified edges or identifiednodes corresponds to at least one of the n-grams.
 11. The method ofclaim 10, wherein each n-gram comprises one or more characters of textentered by the first user.
 12. The method of claim 10, wherein eachn-gram comprises a contiguous sequence of n items from the text query.13. The method of claim 10, wherein identifying one or more edges orsecond nodes comprises: determining a second score for each n-gram thatthe n-gram corresponds to an edge or a second node; selecting one ormore edges having a second score greater than an edge-threshold score,each of the identified edges corresponding to at least one of then-grams; and selecting one or more second nodes having a second scoregreater than a node-threshold score, each of the identified second nodesbeing connected to at least one of the identified edges, each of theidentified second nodes corresponding to at least one of the n-grams.14. The method of claim 13, wherein the second score for each n-gram isa probability that the n-gram corresponds to an edge or a second node.15. The method of claim 1, wherein the structured queries are sent to ainterface associated with a query field for display to the first user.16. The method of claim 1, wherein the text query is inputted by thefirst user at a query field of a webpage or a native applicationassociated with the online social network.
 17. The method of claim 1,further comprising: receiving, from the client device of the first user,a selection of one of the structured queries; and generating one or moresearch results matching the selected structured query, the one or moresearch results corresponding to one or more second nodes, respectively,each second node being connected by an edge corresponding to one of thesocial-graph tokens of the selected structured query to one of a nodecorresponding to one of the social-graph tokens of the selectedstructured query.
 18. The method of claim 1, wherein, for eachstructured query sent to the first user, the grammar used to generatethe structured query comprises one or more query tokens corresponding toone or more identified nodes or identified edges, each of the identifiednodes or identified edges corresponding to at least a portion of thetext query.
 19. One or more computer-readable non-transitory storagemedia embodying software that is operable when executed to: access asocial graph comprising a plurality of nodes and a plurality of edgesconnecting the nodes, each of the edges between two of the nodesrepresenting a single degree of separation between them, the nodescomprising: a first node corresponding to a first user associated withan online social network; and a plurality of second nodes that eachcorrespond to a concept or a second user associated with the onlinesocial network; receive, from a client device of the first user, anunstructured text query inputted by the first user; generate a first setof structured queries based on the text query, each structured query inthe first set corresponding to a grammar of a context-free grammarmodel, wherein each structured query in the first set is based on anatural-language string generated by a grammar of the context-freegrammar model and comprises one or more grammar tokens and one or moresocial-graph tokens, and wherein each social-graph token corresponds toa node of the plurality of nodes or an edge of the plurality of edges;calculate, for each structured query in the first set, a quality scorebased on the text query and the structured query; filter the first setto remove each structured query from the first set having a qualityscore less than a threshold quality score; and send, to the clientdevice of the first user, one or more of the structured queries from thepost-filtered first set, wherein each structured query sent to the firstuser has a quality score greater than or equal to the threshold qualityscore.
 20. A system comprising: one or more processors; and a memorycoupled to the processors comprising instructions executable by theprocessors, the processors operable when executing the instructions to:access a social graph comprising a plurality of nodes and a plurality ofedges connecting the nodes, each of the edges between two of the nodesrepresenting a single degree of separation between them, the nodescomprising: a first node corresponding to a first user associated withan online social network; and a plurality of second nodes that eachcorrespond to a concept or a second user associated with the onlinesocial network; receive, from a client device of the first user, anunstructured text query inputted by the first user; generate a first setof structured queries based on the text query, each structured query inthe first set corresponding to a grammar of a context-free grammarmodel, wherein each structured query in the first set comprises is basedon a natural-language string generated by a grammar of the context-freegrammar model and one or more grammar tokens and one or moresocial-graph tokens, and wherein each social-graph token corresponds toa node of the plurality of nodes or an edge of the plurality of edges;calculate, for each structured query in the first set, a quality scorebased on the text query and the structured query; filter the first setto remove each structured query from the first set having a qualityscore less than a threshold quality score; and send, to the clientdevice of the first user, one or more of the structured queries from thepost-filtered first set, wherein each structured query sent to the firstuser has a quality score greater than or equal to the threshold qualityscore.